﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace YahtzeeAspTest
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        Model.Dice[] tabDices = new Model.Dice[5];
        List<Model.Player> tabPlayer = new List<Model.Player>();
        Model.Game myGame;
        public static Button randomButton;

        protected void Page_Load(object sender, EventArgs e)
        {
            tabPlayer.Add(new Model.Player("jean"));
            tabPlayer.Add(new Model.Player("Pierre"));
            for (int i=0; i<tabDices.Length; i++)
            {
                tabDices[i] = new Model.Dice();
            }            
            Model.Game.Create(tabDices, tabPlayer);
            myGame = Model.Game.Instance;
            foreach (var dice in tabDices)
            {
                dice.Roll();
            }
            randomButton = (Button)this.FindControl("MainContent").FindControl("RandomButton");
        
        }

        protected void RandomButton_Click(object sender, EventArgs e)
        {
            /*for (int i = 0; i < Model.Game.Instance.TableOfDice.Lz; i++)
            {
                Model.Game.Instance.TableOfDice[i].ImageValue = (ImageButton)this.FindControl("MainContent").FindControl("ImageDice" + i +1);
                ImageButton imageButton = (ImageButton)this.FindControl("MainContent").FindControl("ImageDice" + i);
                if (tabDices[i].Locked == false)
                {
                    int randomNumber = random.Next(1, 7);
                    tabDices[i].Value = randomNumber;
                    imageButton.ImageUrl = tabDices[i].ImageValue;                    
                }                
            }*/
            for (int i = 1; i < 6; i++)
            {
                ImageButton imageButton = (ImageButton)this.FindControl("MainContent").FindControl("ImageDice" + i);
                imageButton.ImageUrl = myGame.TableOfDice[i-1].ImageValue; 
            }            
            myGame.throwingDice();            
        }     

        protected void ImageDice1_Click(object sender, ImageClickEventArgs e)
        {
            //Boolean currentStatue = myGame.TableOfDice[0].Locked;
            //Boolean newStatue = currentStatue == true ? false : true;
            //myGame.TableOfDice[0].Locked = newStatue;
            //myGame.TableOfDice[0].ImageValue = "~/DiceLocked" + myGame.TableOfDice[0].Value + ".png";            
            myGame.lockThisDice(0);           
        }

        protected void ImageDice2_Click(object sender, ImageClickEventArgs e)
        {
            //Boolean currentStatue = myGame.TableOfDice[0].Locked;
            //Boolean newStatue = currentStatue == true ? false : true;
            //myGame.TableOfDice[1].Locked = newStatue;          
            //myGame.lockThisDice(1);
            myGame.lockThisDice(1);
        }

        protected void ImageDice3_Click(object sender, ImageClickEventArgs e)
        {
            //Boolean currentStatue = myGame.TableOfDice[0].Locked;
            //Boolean newStatue = currentStatue == true ? false : true;
            //myGame.TableOfDice[2].Locked = newStatue;            
            //myGame.lockThisDice(2);
            myGame.lockThisDice(2);
        }

        protected void ImageDice4_Click(object sender, ImageClickEventArgs e)
        {
            //Boolean currentStatue = myGame.TableOfDice[0].Locked;
            //Boolean newStatue = currentStatue == true ? false : true;
            //myGame.TableOfDice[3].Locked = newStatue;           
           myGame.lockThisDice(3);
        }

        protected void ImageDice5_Click(object sender, ImageClickEventArgs e)
        {
            //Boolean currentStatue = myGame.TableOfDice[0].Locked;
            //Boolean newStatue = currentStatue == true ? false : true;
            //myGame.TableOfDice[4].Locked = newStatue;            
            myGame.lockThisDice(4);
        }
              
        protected void ASRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            ScoreAssocieAsLabel.Text = "coucou";
        }

        protected void DeuxRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void TroisRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void QuatreRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void CinqRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void SixRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void BrelanRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void FullRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void PetiteSuiteRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void GrandeSuiteRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void CarreRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void YahtzeeRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void ChanceRadioButton_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void ValiderChoixButton_Click(object sender, EventArgs e)
        {
            deEnableButton();
            foreach (var dice in tabDices)
            {
                dice.Roll();
            }
        }

          public static void enableButton()
        {           
            randomButton.Enabled = false;
        }

        public static void deEnableButton()
        {
            randomButton.Enabled = true;
        }
        
        public void changePlayer(int i){
            Label namePlayer = this.FindControl("LabelNomJoueur") as Label;
            namePlayer.Text = i.ToString();
        }
    }
}






     
        
      

    

